package com.qujia.customer.enums;

import java.util.HashMap;

/**
 * @date 2023/9/22
 */
public enum CardUseRangeEnum {
    FOR_ALL("1","多站通用"),
    FOR_ONE("2","单站使用"),
    ;

    private final String key;
    private final String name;

    CardUseRangeEnum(String key, String name) {
        this.key = key;
        this.name = name;
    }

    public String getKey() {
        return key;
    }

    public String getName() {
        return name;
    }

    private static HashMap<String, CardUseRangeEnum> keyMap;

    public static CardUseRangeEnum getByKey(String key){
        if (keyMap == null) {
            HashMap<String, CardUseRangeEnum> map = new HashMap<>();
            for (CardUseRangeEnum value : CardUseRangeEnum.values()) {
                map.put(value.getKey(),value);
            }
            keyMap = map;
        }
        return keyMap.get(key);
    }

    public static CardUseRangeEnum getByKey(String key,CardUseRangeEnum defType){
        CardUseRangeEnum type = getByKey(key);
        return type == null ? defType : type;
    }
}
